package com.example.zhou.musichepler;

import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;
import android.util.Log;

import com.example.zhou.musicmodel.MusicBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 11065 on 2016/11/7.
 */

public class MusicHelper {

    String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
    String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
    String[] projection = {
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media.DURATION,
            MediaStore.Audio.Media.DISPLAY_NAME,
    };
    private Context context;

    public MusicHelper(Context context) {
        this.context = context;
    }

    public Cursor getCursor() {
        return context.getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,
                projection, selection, null, sortOrder);
    }

    public List<MusicBean> getList() {
        List<MusicBean> musicBeen = new ArrayList<>();
        Cursor cursor = getCursor();
        Log.e("list", cursor.getCount() + "");
        while (cursor.moveToNext()) {
            /*musicBeen.add(new MusicBean(cursor.getString(0),
                    cursor.getString(1),
                    cursor.getString(2),
                    cursor.getString(3),
                    cursor.getString(4),
                    cursor.getString(5),
                    ));*/
            Log.e("sjss", cursor.getString(0));
        }

        cursor.close();
        return musicBeen;
    }


}
